package com.example.water_quality_analysis.config;

import com.example.water_quality_analysis.job.DataBackupJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzConfig {

    @Bean
    public JobDetail dataBackupJobDetail() {
        return JobBuilder.newJob(DataBackupJob.class)
                .withIdentity("dataBackupJobDetail")
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger dataBackupTrigger() {
        SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
                .withIntervalInSeconds(10) // TODO 此处10秒备份一次，生产环境下需要改为2个月
                .repeatForever();

        return TriggerBuilder.newTrigger()
                .forJob(dataBackupJobDetail())
                .withIdentity("dataBackupTrigger")
                .withSchedule(scheduleBuilder)
                .build();
    }
}
